<?php

class RangeOption extends AppModel
{
	var $useTable = false;
	
	var $fieldProperties = array(
		'min_value' => array('type' => 'text', 'group' => 'add', 'label' => 'Min. Value'),
		'max_value' => array('type' => 'text', 'group' => 'add', 'label' => 'Max. Value'),
	
		'category' => array(
			'type' => 'select', 
			'empty' => '-Select-',
			'label' => 'Select Category', 
			'options' => array(),
			'group' => 'hack',
			'triggers' => array('onChange' => array('update' => 'range_field'))
		),
	);
	
	function getRangeFieldOptions($category)
	{
		$conditions = array('ListCategory.id' => $category);
		$fields = array('listing_type_id');
		$tmp = cri('ListCategory')->find('first', compact('conditions', 'fields'));
		$listing_type_id = $tmp['ListCategory']['listing_type_id'];
		//echo $listing_type_id; exit;
		
		$conditions = array('ListingTypeFieldset.listing_type_id' => $listing_type_id);
		$fields = array('fieldset_id');
		$fieldsets = cri('ListingTypeFieldset')->find('all', compact('conditions', 'fields'));
		$fieldsets = Set::extract('{n}.ListingTypeFieldset.fieldset_id', $fieldsets);
		
		$fieldsetModel = cri('Fieldset');
		$fieldsetModel->recursive = -1;
		$conditions = array('Fieldset.id' => $fieldsets, 'Fieldset.entity' => 'Listing');
		$fields = array('id');
		$fieldsets = $fieldsetModel->find('all', compact('conditions', 'fields'));
		$fieldsets = Set::extract('{n}.Fieldset.id', $fieldsets);
		
		$customFieldModel = $fieldsetModel->CustomField;
		$conditions = array('CustomField.fieldset_id' => $fieldsets, 'CustomField.type' => 'number');
		$fields = array('name', 'label');
		$customFields = $customFieldModel->find('all', compact('conditions', 'fields'));
		
		$customFields = Set::combine($customFields, '{n}.CustomField.name', '{n}.CustomField.label');
		return $customFields;
	}
}

?>